package www.reagnetbox.com.util;

import com.blankj.utilcode.util.TimeUtils;

import org.litepal.LitePal;

import java.util.List;

import www.reagnetbox.com.bean.User;

public class LitePalUtils {

    public static List<User> findAllUsers() {
        return LitePal.findAll(User.class);
    }

    public static void delUser(int id) {
        LitePal.delete(User.class, id);
    }

    public static void updateUserPwd(int id, String newPwd) {
        User user = LitePal.find(User.class, id);
        user.setPwd(newPwd);
        user.save();
    }

    public static void updateUserInfo(int id, String name, String identityNo, String no, String dept) {
        User user = LitePal.find(User.class, id);
        user.setName(name);
        user.setIdentityNo(identityNo);
        user.setNo(no);
        user.setDept(dept);
        user.save();
    }

    public static void saveUser(String username, String pwd, String name, String identityNo, String no, String dept) {
        User user = new User();
        user.setAddDate(TimeUtils.getNowString());
        user.setUsername(username);
        user.setPwd(pwd);
        user.setName(name);
        user.setIdentityNo(identityNo);
        user.setNo(no);
        user.setDept(dept);
        user.save();
    }

    public static void saveUser(String username, String pwd ) {
        User user = new User();
        user.setAddDate(TimeUtils.getNowString());
        user.setUsername(username);
        user.setPwd(pwd);
        user.save();
    }
}
